<template>
  <CardVue height="2rem" title="抽查检查" style="margin-bottom: 0.3rem">
    <div class="layout">
      <div class="layout-t">
        <div
          class="layout-t-item"
          @click="open({ title: '抽查检查', orgFrom: undefined })"
        >
          <div class="layout-t-item-img">
            <img src="@/assets/imgs/largeScreen/icon/j1.svg" alt="" />
          </div>
          <div class="layout-t-item-r">
            <div class="layout-t-item-r-title">检查数量</div>
            <div class="layout-t-item-r-num">{{ info.v6.one }}</div>
          </div>
        </div>
        <div
          class="layout-t-item"
          @click="openPopupProblem({ title: '发现问题', query: { rectifyFlag: undefined } })"
        >
          <div class="layout-t-item-img">
            <img src="@/assets/imgs/largeScreen/icon/j2.svg" alt="" />
          </div>
          <div class="layout-t-item-r">
            <div class="layout-t-item-r-title">发现问题</div>
            <div class="layout-t-item-r-num">{{ info.v7.one }}</div>
          </div>
        </div>
      </div>
      <div class="layout-t-chart">
        <div>
          <Check ref="CheckRef" @change="change" />
        </div>
        <div>
          <Problem ref="ProblemRef" @change="(e) => openPopupProblem(e)" />
        </div>
      </div>
    </div>
  </CardVue>
  <popupVue ref="popupVueRef" />
  <PopupProblem ref="PopupProblemRef" />
</template>
<script setup lang="ts">
import CardVue from '@/views/largeScreen/components/card/card.vue'
import Check from './check/check.vue'
import Problem from './problem/problem.vue'
import { dpcont } from '@/api/spotCheck/spotCheck'
import { onMounted, ref } from 'vue'
import popupVue from './popup.vue'
import PopupProblem from './popup-problem.vue'

interface Info {
  v1: {
    alls: number
    logout: number
    back: number
    uses: number
    st: number
    mf: number
  }
  v2: {
    one: number
    two: number
    three: number
  }
  v3: {
    one: number
    two: number
    three: number
  }
  v4: {
    one: number
    two: number
    three: number
  }
  v5: {
    one: number
    two: number
    three: number
  }
  v6: {
    one: number
    two: number
    three: number
  }
  v7: {
    one: number
    two: number
    three: number
  }
}

const info = ref<Info>({
  v1: {
    alls: 0,
    logout: 0,
    back: 0,
    uses: 0,
    st: 0,
    mf: 0
  },
  v2: {
    one: 0,
    two: 0,
    three: 0
  },
  v3: {
    one: 0,
    two: 0,
    three: 0
  },
  v4: {
    one: 0,
    two: 0,
    three: 0
  },
  v5: {
    one: 0,
    two: 0,
    three: 0
  },
  v6: {
    one: 0,
    two: 0,
    three: 0
  },
  v7: {
    one: 0,
    two: 0,
    three: 0
  }
})

const CheckRef = ref()
const ProblemRef = ref()
onMounted(() => {
  dpcont().then((res) => {
    info.value = res.data
    ProblemRef.value.init(info.value)
    CheckRef.value.init(info.value)
  })
})

const popupVueRef = ref<InstanceType<typeof popupVue> | null>(null)

function open(e) {
  popupVueRef.value?.show(e)
}

const PopupProblemRef = ref<InstanceType<typeof PopupProblem> | null>(null)

function openPopupProblem(e) {
  PopupProblemRef.value?.show(e)
}

function change(name) {
  open({ title: name, orgFrom: name })
}
</script>

<style scoped lang="scss">
.layout {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding-top: 0.1rem;
  .layout-t {
    width: 100%;
    height: 0.4rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
    margin-bottom: 0.1rem;
    .layout-t-item {
      width: 1.4rem;
      height: 100%;
      border-radius: 0.4rem;
      display: flex;
      align-items: center;
      box-sizing: border-box;
      padding: 0 0.1rem;
      background: url('@/assets/imgs/largeScreen/icon/j3.svg') no-repeat;
      background-size: 100% 100%;
      .layout-t-item-img {
        width: 0.2rem;
        height: 100%;
        display: flex;
        align-items: center;
        margin-right: 0.1rem;
        img {
          width: 0.2rem;
          height: 0.2rem;
        }
      }
      .layout-t-item-r {
        flex: 1;
        min-width: 0;
        .layout-t-item-r-title {
          font-size: 0.12rem;
          color: #fff;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          text-align: center;
        }
        .layout-t-item-r-num {
          font-size: 0.14rem;
          color: #fff;
          text-align: center;
        }
      }
    }
  }
  .layout-t-chart {
    width: 100%;
    height: calc(100% - 0.5rem);
    display: flex;
    & > div {
      flex: 1;
      min-width: 0;
      height: 100%;
    }
  }
}
</style>
